import {dateTimeFormatMillisecond} from "../util/formatHandler";
import logConfig from "./LogConfig";


/**
 * 日志类
 */
class Log {
    /**
     * 日志打印对象
     * @private 日志目标,方法或者组件的名字
     */
    private readonly target: string ;
    constructor(target: string) {
        this.target = target + ":" ;
    }


    /**
     * 打印trace日志
     * @param msg 打印日志的说明
     * @param data 打印日志的附加数据
     */
    trace(msg: string,...data: any[]): void{
        logConfig.isEnableTrace &&
        // eslint-disable-next-line no-console
        console.trace("%c" + dateTimeFormatMillisecond(new Date()) + " [TRACE] " + this.target,"color: #DC143C" ,msg,...data) ;
    }

    /**
     * 打印debug日志
     * @param msg 打印日志的说明
     * @param data 打印日志的附加数据
     */
    debug(msg: string,...data: any[]): void{
        logConfig.isEnableDebug &&
        // eslint-disable-next-line no-console
        console.debug("%c" + dateTimeFormatMillisecond(new Date()) + " [DEBUG] " + this.target,"color: #20B2AA",msg,...data) ;
    }
    /**
     * 打印向服务器发送请求时的debug日志
     * @param msg
     * @param data
     */
    request(msg: string,...data: any[]): void{
        logConfig.isEnableRequest &&
        // eslint-disable-next-line no-console
        console.debug("%c" + dateTimeFormatMillisecond(new Date()) + " [REQUEST] " + this.target , "color: #BDB76B",msg,...data) ;
    }
    /**
     * 打印redux日志
     * @param msg 打印日志的说明
     * @param data 打印日志的附加数据
     */
    redux(msg: string,...data: any[]): void{
        logConfig.isEnableRedux &&
        // eslint-disable-next-line no-console
        console.debug("%c" + dateTimeFormatMillisecond(new Date()) + " [REDUX] " + this.target , "color: #F08080",msg,...data) ;
    }

    /**
     * 打印info日志
     * @param msg 打印日志的说明
     * @param data 打印日志的附加数据
     */
    info(msg: string,...data: any[]): void{
        logConfig.isEnableInfo &&
        // eslint-disable-next-line no-console
        console.debug("%c" + dateTimeFormatMillisecond(new Date()) + " [INFO] " + this.target,"color: #228B22",msg,...data) ;
    }

    default(msg: string,...data: any[]): void{
        logConfig.isEnableDefault &&
        // eslint-disable-next-line no-console
        console.debug("%c" + dateTimeFormatMillisecond(new Date()) + " [DEFAULT] " + this.target,"color: #696969",msg,...data) ;
    }

    /**
     * 打印warn日志
     * @param msg 打印日志的说明
     * @param data 打印日志的附加数据
     */
    warn(msg: string,...data: any[]): void{
        logConfig.isEnableWarn &&
        // eslint-disable-next-line no-console
        console.warn(dateTimeFormatMillisecond(new Date()),"[WARN]",this.target,msg,...data) ;
    }

    /**
     * 打印error日志
     * @param msg 打印日志的说明
     * @param data 打印日志的附加数据
     */
    error(msg: string,...data: any[]): void{
        logConfig.isEnableError &&
        // eslint-disable-next-line no-console
        console.error(dateTimeFormatMillisecond(new Date()),"[ERROR]",this.target,msg,...data) ;
    }


}

export default Log ;